//
//  CYHomeVideoDetailsViewController.m
//  cyydt
//
//  Created by chu on 2019/1/21.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYHomeVideoDetailsViewController.h"
#import "ZFAVPlayerManager.h"
#import "ZFPlayerControlView.h"

#import "CYVideoDetail_TitleTableViewCell.h"
#import "CYVideoDetail_CompanyTableViewCell.h"
#import "CYVideoDetail_ShipinTuiJianTableViewCell.h"
#import "CYAdvertTableViewCell.h"
#import "CYCommentModel.h"
#import "CYVideoDetail_CommentTableViewCell.h"
#import "CYProjectDetailViewController.h"

@interface CYHomeVideoDetailsViewController ()<UITableViewDelegate, UITableViewDataSource, HPGrowingTextViewDelegate, PlatformButtonClickDelegate>
{
    UILabel *_titleLabel;
}
@property (nonatomic, assign) CGFloat inputViewHeight;//底部输入框视图
@property (nonatomic, assign) BOOL commentOrReply;//评论还是回复
@property (nonatomic, strong) NSNumber *huifuId;
@property (nonatomic, strong) NSNumber *userid;
@property (nonatomic, strong) UIButton *bottomCollectionBtn;
@property (nonatomic, strong) UIButton *bottomZanBtn;
@property (nonatomic, assign) BOOL isShipin;//是否是给视频点赞
@property (nonatomic, strong) UIImage *shareImage;


@property (nonatomic, strong) UIView *playerContainerView;
@property (nonatomic, strong) ZFPlayerController *player;
@property (nonatomic, strong) ZFPlayerControlView *controlView;
@property (nonatomic, strong) UIButton *playBtn;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *coverImageView;

@property (nonatomic, strong) CYProjectModel *detailModel;
@property (nonatomic, strong) CYProjectModel *adverModel;
@property (nonatomic, strong) NSMutableArray *videoArr;
@property (nonatomic, strong) NSMutableArray *commentArr;

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIView *inputView;
@property (nonatomic, strong) HPGrowingTextView *growingTextView;
@property (nonatomic, strong) UIView *navView;
@property (nonatomic, assign) NSInteger commentAllCount;



@end

@implementation CYHomeVideoDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    __weak typeof(self)weakself = self;

    self.inputViewHeight = 50;
    self.tableView.tableHeaderView = self.playerContainerView;
//    [self.view addSubview:self.playerContainerView];
    ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
    self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.playerContainerView];
    self.player.controlView = self.controlView;
    self.player.shouldAutoPlay = NO;

    /// 设置退到后台继续播放
    self.player.pauseWhenAppResignActive = NO;
    /// 播放完成
    self.player.playerDidToEnd = ^(id  _Nonnull asset) {
        NSLog(@"======播放完毕了");
        weakself.controlView.portraitControlView.playOrPauseBtn.hidden = YES;
        [weakself.playBtn removeFromSuperview];
        [weakself.playerContainerView addSubview:weakself.playBtn];
    };
    self.player.playerReadyToPlay = ^(id<ZFPlayerMediaPlayback>  _Nonnull asset, NSURL * _Nonnull assetURL) {
        NSLog(@"======开始播放了");
        [weakself.coverImageView removeFromSuperview];
        [weakself.playBtn removeFromSuperview];
    };
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self.view addSubview:self.inputView];
    [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakself.view).with.mas_equalTo(50);
        make.left.equalTo(weakself.view).with.mas_offset(0);
        make.right.equalTo(weakself.view).with.mas_offset(0);
        make.height.mas_equalTo(50);
    }];
    [self.growingTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakself.inputView).with.mas_offset(10);
        make.top.equalTo(weakself.inputView).with.mas_offset(5);
        make.right.equalTo(weakself.inputView).with.mas_offset(-10);
        make.bottom.equalTo(weakself.inputView).with.mas_offset(-5);
        
    }];

    self.tableView.estimatedRowHeight = 44;
    if (@available(iOS 11.0, *)) {
        self.tableView.estimatedSectionFooterHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self getDetail];
    [self getVideo];
    [self getComment];
    [self.view addSubview:self.navView];
    
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    if (self.detailModel) {
        if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0) {
            return 3;
        }else if (![NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0){
            return 4;
        }else if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] != 0){
            return 4;
        }else{
            return 5;
        }
    }
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.detailModel) {
        if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0) {
            if (section == 0) {
                return 1;
            }
            if (section == 1) {
                if (self.adverModel) {
                    return self.videoArr.count + 1;
                }
                return self.videoArr.count;
            }
            return self.commentArr.count;
        }else if (![NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0){
            if (section == 0 || section == 1) {
                return 1;
            }
            if (section == 2) {
                if (self.adverModel) {
                    return self.videoArr.count + 1;
                }
                return self.videoArr.count;
            }
            return self.commentArr.count;
        }else if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] != 0){
            if (section == 0 || section == 1) {
                return 1;
            }
            if (section == 2) {
                if (self.adverModel) {
                    return self.videoArr.count + 1;
                }
                return self.videoArr.count;
            }
            return self.commentArr.count;
        }else{
            if (section == 0 || section == 1 || section == 2) {
                return 1;
            }
            if (section == 3) {
                if (self.adverModel) {
                    return self.videoArr.count + 1;
                }
                return self.videoArr.count;
            }
            return self.commentArr.count;
        }
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    __weak typeof(self)weakself = self;
    if (self.detailModel) {
        if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0) {
            if (indexPath.section == 0) {
                CYVideoDetail_TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_TitleTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_TitleTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.model = self.detailModel;
                cell.block = ^{
                    if ([weakself.detailModel.isOpen boolValue]) {
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:NO];
                    }else{
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:YES];
                    }
                    
                    [weakself.tableView reloadData];
                };
                return cell;
            }else if (indexPath.section == 1){
                CYVideoDetail_ShipinTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_ShipinTuiJianTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                if (indexPath.row == self.videoArr.count) {
                    CYAdvertTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYAdvertTableViewCell"];
                    if (!cell) {
                        cell = [[NSBundle mainBundle] loadNibNamed:@"CYAdvertTableViewCell" owner:nil options:nil][0];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.model = self.adverModel;
                    return cell;
                }else{
                    cell.model = self.videoArr[indexPath.row];
                }
                return cell;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                CYCommentModel *comment = self.commentArr[indexPath.row];
                cell.commentModel = comment;
                cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    weakself.commentOrReply = NO;
                    weakself.huifuId = commentId;
                    weakself.userid = userId;
                    [weakself.growingTextView becomeFirstResponder];
                };
                cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    weakself.isShipin = NO;
                    if ([comment.isLike integerValue] == 1) {
                        [weakself cancleZanWithCommentModel:comment];
                    }else{
                        [weakself zanWithCommentModel:comment];
                    }
                };
                return cell;
            }
            
        }else if (![NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0){
            if (indexPath.section == 0) {
                CYVideoDetail_TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_TitleTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_TitleTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.model = self.detailModel;
                cell.block = ^{
                    if ([weakself.detailModel.isOpen boolValue]) {
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:NO];
                    }else{
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:YES];
                    }
                    
                    [weakself.tableView reloadData];
                };
                return cell;
            }else if (indexPath.section == 1){
                CYVideoDetail_CompanyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_CompanyTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CompanyTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.companymodel = self.detailModel;
                
                return cell;
            }else if (indexPath.section == 2){
                
                CYVideoDetail_ShipinTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_ShipinTuiJianTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                if (indexPath.row == self.videoArr.count) {
                    CYAdvertTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYAdvertTableViewCell"];
                    if (!cell) {
                        cell = [[NSBundle mainBundle] loadNibNamed:@"CYAdvertTableViewCell" owner:nil options:nil][0];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.model = self.adverModel;
                    return cell;
                }else{
                    cell.model = self.videoArr[indexPath.row];
                }
                return cell;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                CYCommentModel *comment = self.commentArr[indexPath.row];
                cell.commentModel = comment;
                cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    weakself.commentOrReply = NO;
                    weakself.huifuId = commentId;
                    weakself.userid = userId;
                    [weakself.growingTextView becomeFirstResponder];
                };
                cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    self.isShipin = NO;
                    if ([comment.isLike integerValue] == 1) {
                        [weakself cancleZanWithCommentModel:comment];
                    }else{
                        [weakself zanWithCommentModel:comment];
                    }
                };
                return cell;
            }
            
        }else if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] != 0){
            if (indexPath.section == 0) {
                CYVideoDetail_TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_TitleTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_TitleTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.model = self.detailModel;
                cell.block = ^{
                    if ([weakself.detailModel.isOpen boolValue]) {
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:NO];
                    }else{
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:YES];
                    }
                    [weakself.tableView reloadData];
                };
                return cell;
            }else if (indexPath.section == 1){
                CYVideoDetail_CompanyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_CompanyTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CompanyTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.model = self.detailModel;
                
                return cell;
            }else if (indexPath.section == 2){
                
                CYVideoDetail_ShipinTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_ShipinTuiJianTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                if (indexPath.row == self.videoArr.count) {
                    CYAdvertTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYAdvertTableViewCell"];
                    if (!cell) {
                        cell = [[NSBundle mainBundle] loadNibNamed:@"CYAdvertTableViewCell" owner:nil options:nil][0];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.model = self.adverModel;
                    return cell;
                }else{
                    cell.model = self.videoArr[indexPath.row];
                }
                return cell;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                CYCommentModel *comment = self.commentArr[indexPath.row];
                cell.commentModel = comment;
                cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    weakself.commentOrReply = NO;
                    weakself.huifuId = commentId;
                    weakself.userid = userId;
                    [weakself.growingTextView becomeFirstResponder];
                };
                cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    weakself.isShipin = NO;
                    if ([comment.isLike integerValue] == 1) {
                        [weakself cancleZanWithCommentModel:comment];
                    }else{
                        [weakself zanWithCommentModel:comment];
                    }
                };
                return cell;
            }
            
        }else{
            if (indexPath.section == 0) {
                CYVideoDetail_TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_TitleTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_TitleTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.model = self.detailModel;
                cell.block = ^{
                    if ([weakself.detailModel.isOpen boolValue]) {
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:NO];
                    }else{
                        weakself.detailModel.isOpen = [NSNumber numberWithBool:YES];
                    }
                    
                    [weakself.tableView reloadData];
                };
                return cell;
            }else if (indexPath.section == 1){
                CYVideoDetail_CompanyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_CompanyTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CompanyTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.companymodel = self.detailModel;
                
                return cell;
            }else if (indexPath.section == 2){
                CYVideoDetail_CompanyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_CompanyTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CompanyTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.model = self.detailModel;
                
                return cell;
            }else if (indexPath.section == 3){
                
                CYVideoDetail_ShipinTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_ShipinTuiJianTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                if (indexPath.row == self.videoArr.count) {
                    CYAdvertTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYAdvertTableViewCell"];
                    if (!cell) {
                        cell = [[NSBundle mainBundle] loadNibNamed:@"CYAdvertTableViewCell" owner:nil options:nil][0];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.model = self.adverModel;
                    return cell;
                }else{
                    cell.model = self.videoArr[indexPath.row];
                }
                return cell;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                CYCommentModel *comment = self.commentArr[indexPath.row];
                cell.commentModel = comment;
                cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    weakself.commentOrReply = NO;
                    weakself.huifuId = commentId;
                    weakself.userid = userId;
                    [weakself.growingTextView becomeFirstResponder];
                };
                cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                    weakself.isShipin = NO;
                    if ([comment.isLike integerValue] == 1) {
                        [weakself cancleZanWithCommentModel:comment];
                    }else{
                        [weakself zanWithCommentModel:comment];
                    }
                };
                return cell;
            }
            
        }
    }else{
        if (indexPath.section == 0) {
            CYVideoDetail_TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_TitleTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_TitleTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.detailModel;
            cell.block = ^{
                if ([weakself.detailModel.isOpen boolValue]) {
                    weakself.detailModel.isOpen = [NSNumber numberWithBool:NO];
                }else{
                    self.detailModel.isOpen = [NSNumber numberWithBool:YES];
                }
                
                [weakself.tableView reloadData];
            };
            return cell;
        }else if (indexPath.section == 1){
            CYVideoDetail_CompanyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_CompanyTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CompanyTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.companymodel = self.detailModel;
            
            return cell;
        }else if (indexPath.section == 2){
            CYVideoDetail_CompanyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_CompanyTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CompanyTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.detailModel;
            
            return cell;
        }else if (indexPath.section == 3){
            
            CYVideoDetail_ShipinTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_ShipinTuiJianTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (indexPath.row == self.videoArr.count) {
                CYAdvertTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYAdvertTableViewCell"];
                if (!cell) {
                    cell = [[NSBundle mainBundle] loadNibNamed:@"CYAdvertTableViewCell" owner:nil options:nil][0];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.model = self.adverModel;
                return cell;
            }else{
                cell.model = self.videoArr[indexPath.row];
            }
            return cell;
        }else{
            CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            CYCommentModel *comment = self.commentArr[indexPath.row];
            cell.commentModel = comment;
            cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                weakself.commentOrReply = NO;
                weakself.huifuId = commentId;
                weakself.userid = userId;
                [weakself.growingTextView becomeFirstResponder];
            };
            cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                weakself.isShipin = NO;
                if ([comment.isLike integerValue] == 1) {
                    [weakself cancleZanWithCommentModel:comment];
                }else{
                    [weakself zanWithCommentModel:comment];
                }
            };
            return cell;
        }
        
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.detailModel) {
        if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0) {
            
            if (indexPath.section == 0) {
                if ([self.detailModel.isOpen boolValue]) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.detailModel.content andWidth:kWindowW - 30 fontSize:12];
                    return height + 89;
                }else{
                    return 89;
                }
                return UITableViewAutomaticDimension;
            }else if (indexPath.section == 1){
                if (indexPath.row == self.videoArr.count) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.adverModel.title andWidth:kWindowW - 30 fontSize:16];
                    
                    return height + 128;
                }
                return 105;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                cell.commentModel = self.commentArr[indexPath.row];
                return cell.cellHeight;
            }
        }else if (![NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0){
            
            if (indexPath.section == 0) {
                if ([self.detailModel.isOpen boolValue]) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.detailModel.content andWidth:kWindowW - 30 fontSize:12];
                    return height + 89;
                }else{
                    return 89;
                }
                return UITableViewAutomaticDimension;
            }else if (indexPath.section == 1){
                return 75;
            }else if (indexPath.section == 2){
                if (indexPath.row == self.videoArr.count) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.adverModel.title andWidth:kWindowW - 30 fontSize:16];
                    
                    return height + 128;
                }
                return 105;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                cell.commentModel = self.commentArr[indexPath.row];
                return cell.cellHeight;
            }
        }else if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] != 0){
            
            if (indexPath.section == 0) {
                if ([self.detailModel.isOpen boolValue]) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.detailModel.content andWidth:kWindowW - 30 fontSize:12];
                    return height + 89;
                }else{
                    return 89;
                }
                return UITableViewAutomaticDimension;
            }else if (indexPath.section == 1){
                return 75;
            }else if (indexPath.section == 2){
                if (indexPath.row == self.videoArr.count) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.adverModel.title andWidth:kWindowW - 30 fontSize:16];
                    
                    return height + 128;
                }
                return 105;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                cell.commentModel = self.commentArr[indexPath.row];
                return cell.cellHeight;
            }
        }else{
            
            if (indexPath.section == 0) {
                if ([self.detailModel.isOpen boolValue]) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.detailModel.content andWidth:kWindowW - 30 fontSize:12];
                    return height + 89;
                }else{
                    return 89;
                }
                return UITableViewAutomaticDimension;
            }else if (indexPath.section == 1){
                return 75;
            }else if (indexPath.section == 2){
                return 75;
            }else if (indexPath.section == 3){
                if (indexPath.row == self.videoArr.count) {
                    CGFloat height = [[Tool sharedInstance] heightForString:self.adverModel.title andWidth:kWindowW - 30 fontSize:16];
                    
                    return height + 128;
                }
                return 105;
            }else{
                CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
                cell.commentModel = self.commentArr[indexPath.row];
                return cell.cellHeight;
            }
        }
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (self.detailModel) {
        if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0) {
            if (section == 1 || section == 2) {
                return 40;
            }
            return 0.0001f;
        }else if (![NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0){
            if (section == 2 || section == 3) {
                return 40;
            }
            return 0.0001f;
        }else if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] != 0){
            if (section == 2 || section == 3) {
                return 40;
            }
            return 0.0001f;
        }else{
            if (section == 3 || section == 4) {
                return 40;
            }
            return 0.0001f;
        }
    }
    return 0.0001f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    [view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    if (self.detailModel) {
        if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0) {
            if (section == 1) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = @"视频推荐";
                [view addSubview:label];
                
                UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
                more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
                [more setTitle:@"更多 >" forState:UIControlStateNormal];
                [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
                more.titleLabel.font = [UIFont systemFontOfSize:12];
                [view addSubview:more];
                [more addTarget:self action:@selector(moreVideo:) forControlEvents:UIControlEventTouchUpInside];
                
            }
            if (section == 2) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = [NSString stringWithFormat:@"评论%ld",self.commentAllCount];
                [view addSubview:label];
            }
        }else if (![NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0){
            if (section == 2) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = @"视频推荐";
                [view addSubview:label];
                
                UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
                more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
                [more setTitle:@"更多 >" forState:UIControlStateNormal];
                [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
                more.titleLabel.font = [UIFont systemFontOfSize:12];
                [view addSubview:more];
                [more addTarget:self action:@selector(moreVideo:) forControlEvents:UIControlEventTouchUpInside];
                
            }
            if (section == 3) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = [NSString stringWithFormat:@"评论%ld",self.commentAllCount];
                [view addSubview:label];
            }
        }else if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] != 0){
            if (section == 2) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = @"视频推荐";
                [view addSubview:label];
                
                UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
                more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
                [more setTitle:@"更多 >" forState:UIControlStateNormal];
                [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
                more.titleLabel.font = [UIFont systemFontOfSize:12];
                [view addSubview:more];
                [more addTarget:self action:@selector(moreVideo:) forControlEvents:UIControlEventTouchUpInside];
                
            }
            if (section == 3) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = [NSString stringWithFormat:@"评论%ld",self.commentAllCount];
                [view addSubview:label];
            }
        }else{
            if (section == 3) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = @"视频推荐";
                [view addSubview:label];
                
                UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
                more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
                [more setTitle:@"更多 >" forState:UIControlStateNormal];
                [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
                more.titleLabel.font = [UIFont systemFontOfSize:12];
                [view addSubview:more];
                [more addTarget:self action:@selector(moreVideo:) forControlEvents:UIControlEventTouchUpInside];
                
            }
            if (section == 4) {
                UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
                view1.backgroundColor = [UIColor redColor];
                [view addSubview:view1];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
                label.textColor = RGBOF(0x333333);
                label.font = [UIFont systemFontOfSize:15];
                label.text = [NSString stringWithFormat:@"评论%ld",self.commentAllCount];
                [view addSubview:label];
            }
        }
    }
    return view;
}

- (void)moreVideo:(UIButton *)sender{
    [self.tabBarController setSelectedIndex:2];
    [self.navigationController popToRootViewControllerAnimated:NO];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.detailModel) {
        if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0) {
            if (indexPath.section == 1) {
                if (indexPath.row == self.videoArr.count) {
                    CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
                    detail.model = self.adverModel;
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }else{
                    CYProjectModel *model = self.videoArr[indexPath.row];
                    CYHomeVideoDetailsViewController *detail = [[CYHomeVideoDetailsViewController alloc] init];
                    detail.videoId = [model.ID stringValue];
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }
            }
        }else if (![NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] ==0){
            if (indexPath.section == 1) {
                CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
                detail.isFromVideoDetail = YES;
                detail.model = self.detailModel;
                [[AppDelegate sharedAppDelegate] pushViewController:detail];
            }
            if (indexPath.section == 2) {
                if (indexPath.row == self.videoArr.count) {
                    CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
                    detail.model = self.adverModel;
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }else{
                    CYProjectModel *model = self.videoArr[indexPath.row];
                    CYHomeVideoDetailsViewController *detail = [[CYHomeVideoDetailsViewController alloc] init];
                    detail.videoId = [model.ID stringValue];
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }
            }
        }else if ([NSString stringIsNull:self.detailModel.company_name] && [self.detailModel.itemid integerValue] != 0){
            if (indexPath.section == 2) {
                if (indexPath.row == self.videoArr.count) {
                    CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
                    detail.model = self.adverModel;
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }else{
                    CYProjectModel *model = self.videoArr[indexPath.row];
                    CYHomeVideoDetailsViewController *detail = [[CYHomeVideoDetailsViewController alloc] init];
                    detail.videoId = [model.ID stringValue];
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }
            }
        }else{
            if (indexPath.section == 1) {
                CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
                detail.isFromVideoDetail = YES;
                detail.model = self.detailModel;
                [[AppDelegate sharedAppDelegate] pushViewController:detail];
            }
            if (indexPath.section == 3) {
                if (indexPath.row == self.videoArr.count) {
                    CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
                    detail.model = self.adverModel;
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }else{
                    CYProjectModel *model = self.videoArr[indexPath.row];
                    CYHomeVideoDetailsViewController *detail = [[CYHomeVideoDetailsViewController alloc] init];
                    detail.videoId = [model.ID stringValue];
                    [[AppDelegate sharedAppDelegate] pushViewController:detail];
                }
            }
        }
    }

}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tableView reloadData];
    self.player.viewControllerDisappear = NO;
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = NO;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.player.viewControllerDisappear = YES;
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];

}

- (void)playClick:(UIButton *)sender {
    self.controlView.portraitControlView.playOrPauseBtn.hidden = NO;
    [self.playBtn removeFromSuperview];
    self.player.assetURL = [NSURL URLWithString:self.detailModel.video_url];
}

//- (void)viewWillLayoutSubviews {
//    [super viewWillLayoutSubviews];
//    CGFloat x = 0;
//    CGFloat y = 0;
//    CGFloat w = CGRectGetWidth(self.view.frame);
//    CGFloat h = w*9/16;
//    self.playerContainerView.frame = CGRectMake(x, y, w, h);
//
//    w = 44;
//    h = w;
//    x = (CGRectGetWidth(self.playerContainerView.frame)-w)/2;
//    y = (CGRectGetHeight(self.playerContainerView.frame)-h)/2;
//    self.playBtn.frame = CGRectMake(x, y, w, h);
//
//}

- (UIStatusBarStyle)preferredStatusBarStyle {
    if (self.player.isFullScreen) {
        return UIStatusBarStyleLightContent;
    }
    return UIStatusBarStyleDefault;
}

- (BOOL)prefersStatusBarHidden {
    /// 如果只是支持iOS9+ 那直接return NO即可，这里为了适配iOS8
    return self.player.isStatusBarHidden;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationSlide;
}

- (BOOL)shouldAutorotate {
    return self.player.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    if (self.player.isFullScreen) {
        return UIInterfaceOrientationMaskLandscape;
    }
    return UIInterfaceOrientationMaskPortrait;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint contentOffset = scrollView.contentOffset;
    CGFloat progress = contentOffset.y / (kWindowW * 9 / 16);
    self.navView.backgroundColor = RGBA(246, 246, 246, progress);
    _titleLabel.alpha = progress;
    
}

- (ZFPlayerControlView *)controlView {
    if (!_controlView) {
        _controlView = [[ZFPlayerControlView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowW*9/16)];
        _controlView.fastViewAnimated = YES;
        _controlView.autoHiddenTimeInterval = 5;
        _controlView.autoFadeTimeInterval = 0.5;
    }
    return _controlView;
}

- (UIView *)playerContainerView{
    if (!_playerContainerView) {
        _playerContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowW*9/16)];
        CGFloat w = 44;
        CGFloat h = 44;
        CGFloat x = (CGRectGetWidth(_playerContainerView.frame)-w)/2;
        CGFloat y = (CGRectGetHeight(_playerContainerView.frame)-h)/2;
        self.playBtn.frame = CGRectMake(x, y, w, h);
    }
    return _playerContainerView;
}

- (UIButton *)playBtn {
    if (!_playBtn) {
        _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_playBtn setImage:[UIImage imageNamed:@"video_pause"] forState:UIControlStateNormal];
        [_playBtn addTarget:self action:@selector(playClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _playBtn;
}

- (UITableView *)tableView{
    if (!_tableView) {
//        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kWindowW*9/16, kWindowW, kWindowH - kWindowW*9/16 - self.bottomView.frame.size.height) style:UITableViewStyleGrouped];
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowH - self.bottomView.frame.size.height) style:UITableViewStyleGrouped];

        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackGroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        __weak typeof(self)weakself = self;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakself getVideo];
            [weakself getDetail];
            [weakself getComment];
        }];
        _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [weakself getMoreComment];
        }];
        
        [_tableView registerNib:[UINib nibWithNibName:@"CYVideoDetail_TitleTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYVideoDetail_TitleTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYVideoDetail_CompanyTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYVideoDetail_CompanyTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYVideoDetail_ShipinTuiJianTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYAdvertTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYAdvertTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYVideoDetail_CommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYVideoDetail_CommentTableViewCell"];

    }
    return _tableView;
}

#pragma mark - 获取视频详情
- (void)getDetail{
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"index/view"];
    NSDictionary *param = @{@"id":self.videoId, @"type":@"28"};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"看视频详情 ---- %@",responseResult);
        if ([weakself.tableView.mj_header isRefreshing]) {
            [weakself.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                if ([responseResult[@"data"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *data = responseResult[@"data"];
                    NSMutableDictionary *muDic = [NSMutableDictionary dictionaryWithDictionary:data];
                    [muDic setObject:[NSNumber numberWithBool:NO] forKey:@"isOpen"];
                    weakself.detailModel = [CYProjectModel mj_objectWithKeyValues:muDic];
                    [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:weakself.detailModel.cover_url] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
                        
                    } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
                        weakself.shareImage = image;
                    }];
                    
                    [weakself initBottomViewData];
                    
                    [weakself.controlView showTitle:@"" coverURLString:weakself.detailModel.cover_url fullScreenMode:ZFFullScreenModeAutomatic];
                    [weakself.controlView.coverImageView sd_setImageWithURL:[NSURL URLWithString:weakself.detailModel.cover_url] placeholderImage:[UIImage imageNamed:@"videoPlaceHolde"]];
                    [weakself.playBtn removeFromSuperview];
                    [weakself.playerContainerView addSubview:weakself.playBtn];
                    if ([[self getCurrentNetworkState] isEqualToString:@"WIFI"]) {
                        //wifi
                        weakself.player.assetURL = [NSURL URLWithString:weakself.detailModel.video_url];
                    }else{
                        [LEEAlert alert].config
                        .LeeHeaderColor([UIColor whiteColor])
                        .LeeAddContent(^(UILabel *label) {
                            label.font = [UIFont systemFontOfSize:18];
                            label.textColor = [UIColor blackColor];
                            label.text = @"当前网络环境非WIFI状态,播放视频将消耗您的流量,是否继续播放?";
                        }).LeeAddAction(^(LEEAction *action) {
                            action.titleColor = RGBOF(0x666666);
                            action.borderColor = RGBOF(0xE0DFDF);
                            action.title = @"取消";
                            
                        })
                        .LeeAddAction(^(LEEAction *action) {
                            action.titleColor = RGBOF(0xF43636);
                            action.borderColor = RGBOF(0xE0DFDF);
                            action.title = @"确定";
                            action.clickBlock = ^{
                                weakself.player.assetURL = [NSURL URLWithString:weakself.detailModel.video_url];

                            };
                        })
                        .LeeShow();
                    }
                    
                    [weakself.tableView reloadData];
                }
                
            }else{
                
            }
        }
    }];
}

- (void)initBottomViewData{
    if ([self.detailModel.is_collect integerValue] == 1) {
        self.bottomCollectionBtn.selected = YES;
    }else{
        self.bottomCollectionBtn.selected = NO;
    }
    if ([self.detailModel.is_like integerValue] == 1) {
        self.bottomZanBtn.selected = YES;
    }else{
        self.bottomZanBtn.selected = NO;
    }
}

- (void)getVideo{
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"recommend"];
    NSDictionary *param = @{@"id":self.videoId, @"type":@"28"};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取推荐视频 ---- %@",responseResult);
        if ([weakself.tableView.mj_header isRefreshing]) {
            [weakself.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                if ([data[@"advertisement"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *advertisement = data[@"advertisement"];
                    weakself.adverModel = [CYProjectModel mj_objectWithKeyValues:advertisement];
                }
                NSArray *hotVideos = data[@"hotVideos"];
                for (NSDictionary *dic in hotVideos) {
                    CYProjectModel *model = [CYProjectModel mj_objectWithKeyValues:dic];
                    [weakself.videoArr addObject:model];
                }
                
                [weakself.tableView reloadData];
            }else{
                
            }
        }
    }];
}

- (void)getComment{
    self.page = 1;
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comments"];
    NSDictionary *param = @{@"articleId":self.videoId, @"type":@"28", @"pageNo":@1, @"pageSize":@"10"};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取评论 ---- %@",responseResult);
        if ([weakself.tableView.mj_header isRefreshing]) {
            [weakself.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                weakself.commentAllCount = [data[@"commentNum"] integerValue];
                NSDictionary *comments = data[@"comments"];
                [weakself.commentArr removeAllObjects];
                for (NSDictionary *dic in comments) {
                    CYCommentModel *model = [CYCommentModel modelWithDictionary:dic];
                    [weakself.commentArr addObject:model];
                }
                [weakself.tableView reloadData];
            }else{
                
            }
        }
    }];
}

- (void)getMoreComment{
    self.page ++;
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comments"];
    NSDictionary *param = @{@"articleId":self.videoId, @"type":@"28", @"pageNo":[NSNumber numberWithInteger:self.page], @"pageSize":@"10"};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取评论 ---- %@",responseResult);
        if ([weakself.tableView.mj_footer isRefreshing]) {
            [weakself.tableView.mj_footer endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
            weakself.page --;
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                NSDictionary *comments = data[@"comments"];
                for (NSDictionary *dic in comments) {
                    CYCommentModel *model = [CYCommentModel modelWithDictionary:dic];
                    [weakself.commentArr addObject:model];
                }
                [weakself.tableView reloadData];
            }else{
                weakself.page --;
            }
        }
    }];
}

- (NSMutableArray *)videoArr{
    if (!_videoArr) {
        _videoArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _videoArr;
}

- (NSMutableArray *)commentArr{
    if (!_commentArr) {
        _commentArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _commentArr;
}

- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
        if (HX_IS_IPhoneX_All) {
            _bottomView.frame = CGRectMake(0, kWindowH - 83, kWindowW, 83);
        }else{
            _bottomView.frame = CGRectMake(0, kWindowH - 48, kWindowW, 48);
        }
        
        UIView *contrainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 48)];
        [_bottomView addSubview:contrainerView];
        

        
        NSArray *images = @[@"ksp_pl", @"ksp_sc", @"ksp_zan"];
        CGFloat width = 20;
        CGFloat height = 20;
        UIButton *comBtn = nil;
        for (int i = 2; i >= 0; i--) {
            UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [commentBtn setFrame:CGRectMake(kWindowW - 25 - 20 - (2 - i) * width - (2 - i) * 25, 12, width, height)];
            [commentBtn setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
            [commentBtn addTarget:self action:@selector(btnsClick:) forControlEvents:UIControlEventTouchUpInside];
            [contrainerView addSubview:commentBtn];
            commentBtn.tag = i;
            if (i == 1) {
                self.bottomCollectionBtn = commentBtn;
                [commentBtn setImage:[UIImage imageNamed:@"video_collect_selected"] forState:UIControlStateSelected];
            }
            if (i == 2) {
                self.bottomZanBtn = commentBtn;
                [commentBtn setImage:[UIImage imageNamed:@"zan_sel"] forState:UIControlStateSelected];
            }
            if (i == 0) {
                comBtn = commentBtn;
            }
        }
        
        UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [commentBtn setFrame:CGRectMake(15, 9, CGRectGetMinX(comBtn.frame) - 30, 30)];
        commentBtn.layer.cornerRadius = 15;
        commentBtn.layer.borderWidth = 1;
        commentBtn.layer.borderColor = RGBOF(0xe3e3e3).CGColor;
        commentBtn.layer.masksToBounds = YES;
        [commentBtn setBackgroundColor:RGBOF(0xf7f7f7)];
        [commentBtn setTitle:@"   写评论" forState:UIControlStateNormal];
        [commentBtn setImage:[UIImage imageNamed:@"wd_wdwd"] forState:UIControlStateNormal];
        [commentBtn setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
        commentBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [commentBtn setContentEdgeInsets:UIEdgeInsetsMake(0, 25, 0, 0)];
        [commentBtn addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
        [contrainerView addSubview:commentBtn];
    }
    return _bottomView;
}

#pragma mark - 评论
- (void)commentAction{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    self.commentOrReply = YES;
    [self.growingTextView becomeFirstResponder];
}

- (void)btnsClick:(UIButton *)sender{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    if (sender.tag == 0) {
        //评论
        [self commentAction];
    }else if (sender.tag == 1){
        //收藏
        if ([self.detailModel.is_collect integerValue] == 1) {
            [self cancleCollection];
        }else{
            [self collection];
        }
    }else{
        //点赞
        self.isShipin = YES;
        if ([self.detailModel.is_like integerValue] == 1) {
            [self cancleZanWenZhang];
        }else{
            [self zanWenZhang];
        }
    }
}

#pragma mark - 收藏取消收藏
- (void)cancleCollection{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@/%@",User_HOST, @"collection",self.detailModel.ID];
    NSDictionary *param = @{@"type":@"28", @"articleId":self.detailModel.ID};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] deleteDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"取消收藏 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                weakself.detailModel.is_collect = [NSNumber numberWithInteger:2];
                [weakself initBottomViewData];

            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

- (void)collection{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"collection/addCollect"];
    NSDictionary *param = @{@"type":@28, @"articleId":self.detailModel.ID};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"收藏本咨询 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                weakself.detailModel.is_collect = [NSNumber numberWithInteger:1];
                [weakself initBottomViewData];
                
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

#pragma mark - 给视频赞和取消点赞
- (void)zanWenZhang{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"addLike"];
    NSDictionary *param = @{@"type":@1, @"likeId":self.detailModel.ID, @"origin":@"28", @"toLikerId":self.detailModel.user_id};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"给文章点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                weakself.detailModel.is_like = [NSNumber numberWithInteger:1];
                [weakself initBottomViewData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}
- (void)cancleZanWenZhang{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"cancleLike"];
    NSDictionary *param = @{@"type":@1, @"articleId":self.detailModel.ID, @"origin":@"28", @"toLikerId":self.detailModel.user_id};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"给文章取消点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                weakself.detailModel.is_like = [NSNumber numberWithInteger:2];
                [weakself initBottomViewData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

#pragma mark - 给评论赞和取消点赞
- (void)cancleZanWithCommentModel:(CYCommentModel *)commentModel{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"cancleLike"];
    NSDictionary *param = @{@"type":@2, @"articleId":commentModel.ID, @"origin":@"28", @"toLikerId":commentModel.userId};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"取消点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                commentModel.isLike = [NSNumber numberWithInteger:2];
                NSInteger tag = [commentModel.likeNumber integerValue];
                commentModel.likeNumber = [NSString stringWithFormat:@"%ld",(tag - 1)];
                [weakself.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

- (void)zanWithCommentModel:(CYCommentModel *)commentModel{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"addLike"];
    NSDictionary *param = @{@"type":@2, @"likeId":commentModel.ID, @"origin":@"28", @"toLikerId":commentModel.userId};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"赞评论 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                commentModel.isLike = [NSNumber numberWithInteger:1];
                NSInteger tag = [commentModel.likeNumber integerValue];
                commentModel.likeNumber = [NSString stringWithFormat:@"%ld",(tag + 1)];
                [weakself.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

#pragma mark - 发布评论
- (void)fasongpinglunWithText:(NSString *)content{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comment"];
    NSDictionary *param = @{@"toUserId":self.detailModel.user_id, @"type":@"28", @"articleId":self.videoId, @"content":content};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"发布评论 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [weakself getComment];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];

            }
        }
    }];
}

#pragma mark - 发布回复
- (void)fasongHuiFuWithText:(NSString *)content{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"inserReply"];
    NSDictionary *param = @{@"toUserId":self.userid, @"type":@"28", @"commentId":self.huifuId, @"content":content};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"发布回复 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [weakself getComment];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];

            }
        }
    }];
}

- (UIView *)inputView{
    if (!_inputView) {
        _inputView = [[UIView alloc] init];
        _inputView.backgroundColor = [UIColor whiteColor];
        HPGrowingTextView *group = [[HPGrowingTextView alloc] init];
        self.growingTextView = group;
        group.delegate = self;
        group.font = [UIFont systemFontOfSize:14];
        group.minNumberOfLines = 1;
        group.maxNumberOfLines = 5;
        group.placeholder = @"输入评论";
        group.returnKeyType = UIReturnKeySend;
        group.enablesReturnKeyAutomatically = YES;
        group.backgroundColor = RGBOF(0xf6f6f6);
        group.layer.cornerRadius = 5;
        [_inputView addSubview:group];
        
    }
    return _inputView;
}

#pragma mark - UIKeyboardNotification

- (void)keyboardWillShow:(NSNotification *)notification
{
    CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

    __weak typeof(self)weakself = self;
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [weakself.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(weakself.view).with.mas_equalTo(-endRect.size.height);
            make.left.equalTo(weakself.view).with.mas_offset(0);
            make.right.equalTo(weakself.view).with.mas_offset(0);
            make.height.mas_equalTo(50);
        }];
        [weakself.view layoutIfNeeded];
    } completion:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    __weak typeof(self)weakself = self;
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [weakself.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(weakself.view).with.mas_equalTo(weakself.inputViewHeight);
            
        }];
        [weakself.view layoutIfNeeded];
    } completion:nil];
}

#pragma mark - UITextViewDelegate

- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height
{
    self.inputViewHeight = height + 14;
    [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(height + 14);
    }];
    [self.view layoutIfNeeded];
}

- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView
{
    [self.growingTextView resignFirstResponder];
    return YES;
}

- (BOOL)growingTextView:(HPGrowingTextView *)growingTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    //判断是回车键就发送出去
    if ([text isEqualToString:@"\n"])
    {
        if (self.commentOrReply) {
            [self fasongpinglunWithText:self.growingTextView.text];
        }else{
            [self fasongHuiFuWithText:self.growingTextView.text];
        }
        self.growingTextView.text = @"";
        [self.growingTextView resignFirstResponder];
        [self.tableView reloadData];
        return NO;
    }
    return YES;
}

- (void)growingTextViewDidChange:(HPGrowingTextView *)growingTextView
{
    UITextRange *selectedRange = growingTextView.internalTextView.markedTextRange;
    NSString *newText = [growingTextView.internalTextView textInRange:selectedRange];
    
    if (newText.length < 1)
    {
        // 高亮输入框中的@
        UITextView *textView = self.growingTextView.internalTextView;
        NSRange range = textView.selectedRange;
        
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:textView.text];
        [string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, string.string.length)];
        
        
        textView.attributedText = string;
        textView.selectedRange = range;
    }
}

- (void)growingTextViewDidChangeSelection:(HPGrowingTextView *)growingTextView
{
    // 光标不能点落在@词中间
    NSRange range = growingTextView.selectedRange;
    if (range.length > 0)
    {
        // 选择文本时可以
        return;
    }
    
}

- (UIView *)navView {
    if (!_navView) {
        _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, Height_NavBar)];
        _navView.backgroundColor = RGBA(246, 246, 246, 0);
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWindowW - 150, 44)];
        _titleLabel = label;
        label.alpha = 0;
        label.font = [UIFont systemFontOfSize:17];
        label.textAlignment = NSTextAlignmentCenter;
        label.center = CGPointMake(kWindowW / 2, Height_StatusBar + 22);
        label.textColor = [UIColor blackColor];
        [_navView addSubview:label];
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(15, Height_StatusBar, 44, 44)];
        [btn setImage:[UIImage imageNamed:@"cydz_back"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(popAction:) forControlEvents:UIControlEventTouchUpInside];
        [_navView addSubview:btn];
        
        UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(kWindowW - 44 - 15, Height_StatusBar, 44, 44)];
        [btn1 setImage:[UIImage imageNamed:@"cydz_fenx"] forState:UIControlStateNormal];
        [btn1 addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
        [_navView addSubview:btn1];
    }
    return _navView;
}

- (void)popAction:(UIButton *)sender{
    [[AppDelegate sharedAppDelegate] popViewController];
}

- (void)shareAction:(UIButton *)sender{
    YSActionSheetView * ysSheet=[[YSActionSheetView alloc]initNYSView];
    ysSheet.delegate=self;
    [[UIApplication sharedApplication].keyWindow addSubview:ysSheet];
}

- (void) customActionSheetButtonClick:(YSActionSheetButton *) btn
{
    if (self.detailModel == nil) {
        return;
    }
    [self shareImageToPlatformType:btn.tag];
}

- (void)shareImageToPlatformType:(NSInteger)platformType
{
    //2:qq 3:qzone 0:weixin 1:pengyouquan
    //创建分享消息对象
    
    if (platformType == 2 || platformType == 3) {
        
        NSString *utf8String = self.detailModel.share_url;
        NSString *title = self.detailModel.title;
        NSString *description = self.detailModel.shareContent;
        UIImage *image = nil;
        if (!self.shareImage) {
            image = [UIImage imageNamed:@"login_logo"];
        }else{
            image = self.shareImage;
        }
        QQApiVideoObject *newsObj = [QQApiVideoObject
                                     objectWithURL:[NSURL URLWithString:utf8String] title:title description:description previewImageData:UIImageJPEGRepresentation(image, 1)];
        SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
        if (platformType == 2) {
            //将内容分享到qq
            [QQApiInterface sendReq:req];
        }else{
            //将内容分享到qzone
            [QQApiInterface SendReqToQZone:req];
        }
        
    }else{
        SendMessageToWXReq *req1 = [[SendMessageToWXReq alloc]init];
        
        // 是否是文档
        req1.bText =  NO;
        
        //    WXSceneSession  = 0,        /**< 聊天界面    */
        //    WXSceneTimeline = 1,        /**< 朋友圈      */
        //    WXSceneFavorite = 2,
        
        
        req1.scene = (int)platformType;
        
        //创建分享内容对象
        WXMediaMessage *urlMessage = [WXMediaMessage message];
        urlMessage.title = self.detailModel.title;//分享标题
        urlMessage.description = self.detailModel.shareContent;//分享描述

        if (!self.shareImage) {
            [urlMessage setThumbImage:[UIImage imageNamed:@"login_logo"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }else{
            [urlMessage setThumbImage:self.shareImage];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }
        //创建多媒体对象
        
        NSString *kLinkURL = self.detailModel.share_url;
        
        WXVideoObject *video = [WXVideoObject object];
        video.videoUrl = kLinkURL;//分享链接
        
        //完成发送对象实例
        urlMessage.mediaObject = video;
        req1.message = urlMessage;
        
        //发送分享信息
        [WXApi sendReq:req1];
        
    }
}

#pragma mark - 获取当前网络状态

/**
 
 *  获取当前网络状态
 
 *
 
 *  0:无网络 & 1:2G & 2:3G & 3:4G & 5:WIFI
 
 */

- (NSString *)getCurrentNetworkState {
    
    Reachability *reachability   = [Reachability reachabilityWithHostName:@"www.apple.com"];
    NetworkStatus internetStatus = [reachability currentReachabilityStatus];
    NSString *net = @"WIFI";
    switch (internetStatus) {
        case ReachableViaWiFi:
            net = @"WIFI";
            break;
            
        case ReachableViaWWAN:
            net = @"蜂窝数据";
            //net = [self getNetType ];   //判断具体类型
            break;
            
        case NotReachable:
            net = @"当前无网路连接";
            
        default:
            break;
    }
    
    return net;
    
}

- (UIImageView *)coverImageView{
    if (!_coverImageView) {
        _coverImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowW*9/16)];
    }
    return _coverImageView;
}

@end
